home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group96a.txt / 000074_icon-group-sender _Wed Apr 10 14:23:35 1996.msg < prev    next >
Internet Message Format  |  1996-09-05  |  3KB

  1. Received: by cheltenham.cs.arizona.edu; Wed, 10 Apr 1996 16:20:25 MST
  2. Date: Wed, 10 Apr 1996 14:23:35 -0700
  3. From: kwalker@orville.premenos.com (Ken Walker)
  4. Message-Id: <199604102123.OAA08553@varda.premenos.com>
  5. To: icon-group@cs.arizona.edu
  6. Subject: Re: How to think about Icon?
  7. Mime-Version: 1.0
  8. Content-Type: text/plain; charset=us-ascii
  9. Content-Transfer-Encoding: 7bit
  10. Content-Md5: JSmsXmNGzG1t3kCMAvGGZQ==
  11. Errors-To: icon-group-errors@cs.arizona.edu
  12. Status: O
  13.  
  14. > From: seebs@solutions.solon.com (Peter Seebach)
  15. > Subject: How to think about Icon?
  16. > ...
  17. > What kind of conceptual model do you use for programming in Icon?  How
  18. > do you use it differently from "simple" procedural languages, like C
  19. > or Perl?
  20.  
  21. I find it is easiest if I don't try to embrace the full potential of
  22. generators and goal-directed evaluation all at once. The concept of
  23. a "result sequence" can be very helpful. It lets you think independently
  24. about all the potential results of a generator and how the results are used.
  25. The concept becomes a little muddied when data structures used to generate
  26. results change between results (for example, queens.icn in the Icon Program
  27. Library modifies the chess board used to test for moves as it is generating
  28. solutions), but in many cases the concept can be applied very cleanly.
  29.  
  30. The concept of a result sequence helps you write generative procedures by
  31. allowing you to be concerned only with the sequence in which suspend
  32. expressions are executed and not be concerned with why the procedure is
  33. being resumed. On the other side of the coin, once you convince yourself
  34. that an expression produces the sequence of values you want, you can 
  35. concentrate on how the sequence is used and forget about how it is 
  36. produced.
  37.  
  38. There are two basic paradigms for using generator: interation and goad-directed
  39. evaluation. In interation, you are using all the values of a generator. For
  40. example:
  41.  
  42.      every write(!a)
  43.      
  44. writes all the values produced by !a.
  45.      
  46. In goal-directed evaluation, you are looking for a value from a generator
  47. that meets a condition. For example, the expression
  48.  
  49.     write(s ? (tab(find("name:")) & tab(upto(';'))))
  50.     
  51. locates the first position in s that contains "name:" and prints the
  52. string from there upto to the next ";", if there is one.
  53.  
  54. Of course, things can get more complicated; you can also use this expression
  55. in interation to produce a sequence of results. The following program
  56. demonstrate's Marc Espie's warning about being careful when combining
  57. generators and resuming them.
  58.  
  59.     procedure main()
  60.         local s
  61.  
  62.         s := "testing name:Jack; name:Jill;"
  63.         every write(s ? (tab(find("name:")) & tab(upto(';'))))
  64.     end
  65.  
  66. I expected it to print two results and it printed three:
  67.  
  68.     name:Jack
  69.     name:Jack; name:Jill
  70.     name:Jill
  71.  
  72. I need to limit tab(upto(';')) to one result if I want to print
  73. just the 1st and 3rd result.
  74.  
  75. Ken Walker, kwalker@premenos.com
  76. Premenos Coporation, Concord, Ca. 94520
  77.